package org.rcy.framework.storage.config;

import org.rcy.framework.api.storage.StorageService;
import org.rcy.framework.api.storage.StorageStrategy;
import org.rcy.framework.storage.HuaweiCloudObsService;
import org.rcy.framework.storage.StorageServiceImpl;
import org.rcy.framework.storage.strategy.HuaweiCloudStorageStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * @author 吴康桥
 * @Description
 * @date 2023/7/4 14:04
 */

@Configuration
@EnableConfigurationProperties({HuaweiCloudObsProperties.class})
public class StorageAutoConfiguration {

	@Autowired
	private HuaweiCloudObsProperties obsProperties;

	@Bean
	public StorageStrategy huaweiStorageStrategy() {
		HuaweiCloudStorageStrategy storageStrategy = new HuaweiCloudStorageStrategy(huaweiCloudObsPrivBucket(),huaweiCloudObsPublicBucket());
		return storageStrategy;
	}

	@Bean
	public StorageService storageService(List<StorageStrategy> storageStrategies) {
		StorageService storageService = new StorageServiceImpl(storageStrategies);
		return storageService;
	}

	@Bean
	public HuaweiCloudObsService huaweiCloudObsPublicBucket(){
		return new HuaweiCloudObsService(obsProperties.getAccessId(), obsProperties.getAccessKey(),obsProperties.getEndpoint(),obsProperties.getBucketPublic());
	}

	@Bean
	public HuaweiCloudObsService huaweiCloudObsPrivBucket(){
		return new HuaweiCloudObsService(obsProperties.getAccessId(),obsProperties.getAccessKey(),obsProperties.getEndpoint(),obsProperties.getBucketPrivate());
	}
}
